#include "delay.h"
#include "system_stm32f4xx.h"
#include "stm32f429xx.h"

void delay_us(uint16_t us) {
    SysTick->CTRL = 0; // Disable SysTick
    SysTick->LOAD = (SystemCoreClock/1000000)*us - 1; // Count from
    SysTick->VAL = 0; // Clear current val as well as count flag
    SysTick->CTRL = 5; // Enable SysTick timer with processor clock
    while ((SysTick->CTRL & 0x00010000) == 0); // Wait until count done
    SysTick->CTRL = 0; // Disable SysTick
}

void delay_ms(uint16_t ms) {
    while (ms--) {
        delay_us(1000);
    }
}

void delay_s(uint32_t s) {
    while (s--) {
        delay_ms(1000);
    }
}
